package com.study.task;

import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Random;

@Slf4j
@Component
public class ScheduleTask {

    @Scheduled(cron = "0/2 * * * * ?")
    public void task() throws InterruptedException {
        log.info("执行任务1》》》》》》》》》》》");
        Thread.sleep(3000);
    }

    @Scheduled(cron = "0/2 * * * * ?")
    public void task1() throws InterruptedException {
        log.info("执行任务2》》》》》》》》》》》");
        Thread.sleep(3000);
    }

//    //@Scheduled(fixedDelay = 5000)
//    @Scheduled(fixedRate = 5000,initialDelay = 8000)
//    public void task1() throws InterruptedException {
//        int time = (new Random().nextInt(7) + 1) * 1000;
//        log.info("执行任务2》》》》》》》》》》》, 需要" + time + "毫秒");
//        Thread.sleep(time);
//    }

    //项目启动后task和task1 两个任务自动执行
}
